package com.woniu.smart.controller;

import com.woniu.smart.entity.Buildfloor;
import com.woniu.smart.service.BuildfloorService;
import com.woniu.smart.util.Result;
import com.woniu.smart.vo.BuildfloorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 晨星
 * @date 2022/10/21/15:40
 */
@RestController
@RequestMapping("buildfloor")
public class BuildfloorController {
    
    @Autowired
    private BuildfloorService buildfloorService;

    /**
     * 查询房间的信息
     *
     * @author 晨星
     * @date 2022/10/25 15:07
     * @param id 楼宇id
     * @return java.util.List<com.woniu.smart.vo.BuildfloorVo>
     **/
    @PostMapping("{id}")
    public Result queryAllBuildfloor(@PathVariable Long id){
        List<BuildfloorVo> list = buildfloorService.selectAllBuildfloor(id);
        return Result.ok().data("list",list);
    }



    /**
     * 新增楼层信息
     *
     * @author 晨星
     * @date 2022/10/21 14:31
     * @param buildfloor 楼层的实体类
     * @return com.woniu.smart.util.Result
     **/
    @PostMapping("")
    public Result insertBuildfloor(@RequestBody Buildfloor buildfloor){
        buildfloorService.insertSelective(buildfloor);
        return Result.ok();
    }

    /**
     * 修改楼层信息
     *
     * @author 晨星
     * @date 2022/10/20 21:44
     * @param buildfloor 楼层的实体类
     * @return com.woniu.smart.util.Result
     **/
    @PutMapping("")
    public Result updateBuildfloor(@RequestBody Buildfloor buildfloor){
        buildfloorService.updateByPrimaryKeySelective(buildfloor);
        return Result.ok();
    }

    /**
     * 根据id删除楼层
     *
     * @author 晨星
     * @date 2022/10/21 14:31
     * @param id 主键id
     * @return com.woniu.smart.util.Result
     **/
    @DeleteMapping("{id}")
    public Result deleteBuildfloorById(@PathVariable Long id){
        buildfloorService.deleteByPrimaryKey(id);
        return Result.ok();
    }
}
